package _05xpath相对路径;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

import java.util.List;

public class Demo5 {
    public static void main(String[] args) throws DocumentException {
        SAXReader reader = new SAXReader();
        Document document = reader.read("Day_14\\xpath_contact.xml");

        Element root = document.getRootElement();
        List<Element> eles = root.elements();
        for (Element ele : eles) {
            System.out.println(ele.getName());
        }

        ///相对路径   .对应的是前面的root
        List<Node> nodes = root.selectNodes("./contact/name");

        for (Node node : nodes) {

            System.out.println(node.getText());
        }
        System.out.println("---------------");


        Node node = root.selectSingleNode("./contact/brother/name");
        System.out.println(node.getText());


    }
}
